jsun.run(function() {
//////////////////////////////////////////////////////

function OrderApply() {

   var _this = this;
    jsun.json.load(function(p) {
        if (p.STAT !== 'NULL') {

            var dlg = new jsun.dialog({title: "Выдача"}),
                param = 'u=Lib&m=Lib\\Reader/IssueDialog'
                    + '&order_id=' + _this.getAttribute("data-order")
                    + '&item_id=' + p.STAT;

            jsun.html.insert(dlg.content.v, jsun.html.sync_load(param));
            dlg.show();

        } else {
            jsun.dialog.warning("Информация",
                "Нет доступных экземпляров").show();
        }
    }, "u=Edition/AvailiableEdit&edit_id="
        + this.getAttribute("data-edit"));
    return true;
}

function OrderCancel() {
    jsun.ajax.send_request({ asyn: false,
        param: "u=Reader/CancelOrder&order_id="
            + this.getAttribute("data-order") });

    jsun.json.load(function(p) {
        var div = jsun('#ReaderOrders');
        div.innerHTML = "";
        div.appendChild(jsun.dom.from_json(p));
    }, 'u=Lib&m=Lib\\Reader/OrderList&user_id=' + jsun('#ReaderId').value);

    return true;
}

var list = jsun("#ReaderOrderTable").firstChild.childNodes;

for (var i = 1; i < list.length; ++i) {
    jsun.dom.mix(list[i].childNodes[2].firstChild).event({ onclick: OrderApply });
    jsun.dom.mix(list[i].childNodes[3].firstChild).event({ onclick: OrderCancel });
}

///////////////////////////////////////////////////////
});
